package com.mju.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.mju.service.elastic.ElasticService;
import com.mju.utils.RespData;

import co.elastic.clients.elasticsearch._types.ElasticsearchException;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
public class ElasticController {

	@Autowired
	private ElasticService elasticService;

	@GetMapping("/elastic/toDoc")
	public RespData toDoc() throws ElasticsearchException, IOException {
		elasticService.createIndex();
		elasticService.batchToDoc();
		return RespData.success("导入ElasticSearch文档成功");
	}
	
	@GetMapping("/elastic/search")
	public RespData search(String keyword) throws ElasticsearchException, IOException {
		List<Map<String,String>> list= elasticService.esByMemo(keyword);
		return RespData.data(list);
	}
}
